package com.zusmart.core.config.support;

import com.zusmart.base.util.StringUtils;
import com.zusmart.core.config.ConfigSource;

public abstract class AbstractConfigSource implements ConfigSource {

	protected final String configFile;
	protected final String configFileExtension;

	protected AbstractConfigSource(String configFile, String configFileExtension) {
		if (StringUtils.isBlank(configFile)) {
			throw new IllegalArgumentException("config file must not be null");
		}
		if (StringUtils.isBlank(configFileExtension)) {
			throw new IllegalArgumentException("config file extension must not be null");
		}
		this.configFile = configFile;
		this.configFileExtension = configFileExtension;
	}

	@Override
	public String getConfigFile() {
		return this.configFile;
	}

	@Override
	public String getConfigFileExtension() {
		return this.configFileExtension;
	}

	@Override
	public String getConfigData(String configName) {
		return this.getConfigData(configName, null);
	}

	@Override
	public int hashCode() {
		return this.toString().hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (null == obj) {
			return false;
		}
		if (obj instanceof AbstractConfigSource) {
			return obj.toString().equals(this.toString());
		}
		return false;
	}

	@Override
	public String toString() {
		return String.format("[ConfigSource]%s.%s", this.getConfigFile(), this.getConfigFileExtension());
	}

}